<?php
require_once(dirname(__FILE__).'/inc/header.php');

if ($_GET['a'] === 'init') {
	if ($_SESSION['user_id']) {
		echo 'UM_OB.jsonp_callback("show_save")';
	} else {
		echo 'UM_OB.jsonp_callback("show_login")';
	}
} elseif ($_GET['a'] === 'logout') {
	$data_login = new data_login();
	$data_login->clear_all();
	echo 'UM_OB.jsonp_callback("show_login")';
} elseif ($_GET['a'] === 'check_login') {
	if ($_GET['b']==='weibo' or $_GET['b']==='renren' or $_GET['b']==='kaixin001' or $_GET['b']==='qqwb') {		// 检查具体社交账号的登陆情况
		/**
		 * 当在save页面中绑定账号的授权过期，需要重新登陆验证时，当iframe刷新时调用此check login并指定社交账号类型
		 * 如果检查该账号登陆成功，则重新加载save页面，否则不用有返回，继续等待
		 */
		if ($_SESSION['user_id']) {
			$data_user = new data_user();
			$u = $data_user->one($_SESSION['user_id']);
			if ($_GET['b']		=== 'weibo'	and $u['weibo_id']	and $u['weibo_token']['access_token']) {
				echo 'UM_OB.jsonp_callback("show_save")';
			} elseif ($_GET['b']	=== 'renren'	and $u['renren_id']	and $u['renren_token']['access_token']) {
				echo 'UM_OB.jsonp_callback("show_save")';
			} elseif ($_GET['b']	=== 'kaixin001'	and $u['kaixin001_id']	and $u['kaixin001_token']['access_token']) {
				echo 'UM_OB.jsonp_callback("show_save")';
			} elseif ($_GET['b']	=== 'qqwb'	and $u['qqwb_id']	and $u['qqwb_token']['access_token']) {
				echo 'UM_OB.jsonp_callback("show_save")';
			}
		}
	} else {
		if ($_SESSION['user_id']) {
			echo 'UM_OB.jsonp_callback("show_save")';
		} else {
			//echo 'UM_OB.jsonp_callback("show_login")';
		}
	}
}
?>
